package com.lfg.leetcode.leetcode0;

public class No98isValidBST {

    public static void main(String[] args) {
        TreeNode root = new TreeNode(2147483647);
//        root.left = new TreeNode(1);
//        root.right = new TreeNode(3);
        boolean ret = isValidBST(root);
        System.out.println("[" + ret + "]");
    }

    public static boolean isValidBST(TreeNode root) {
        return isValidBST(root, null, null);
    }

    public static boolean isValidBST(TreeNode root, Integer min, Integer max) {
        if (null == root) {
            return true;
        }
        if ((null != min && root.val <= min) || (max != null && root.val >= max)) {
            return false;
        }
        if (!isValidBST(root.left, min, root.val)) {
            return false;
        }
        return isValidBST(root.right, root.val, max);
    }
}

